import router from './index'
import store from '../store'

const whiteList = ['/login'] // 白名单

router.beforeEach((to, from, next) => {
  // to and from are both route objects. must call `next`.
  const token = store.getters.token ? store.getters.token : ''
  if (token) {
    next()
  } else {
    console.log('token')
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next(`/login?redirect=${to.path}`)
    }
  }
})
